import sys
import os
from PySide6.QtGui import QPaintEvent
from PySide6.QtWidgets import *
from PySide6.QtGui import *
from PySide6.QtCore import *

class Demo(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.parent = parent
        layout = QVBoxLayout()
        layout.setAlignment(Qt.AlignmentFlag.AlignTop)
        
        toolBar=QToolBar()

        toolBar.addWidget(QLabel("Color:"))        
        cb=QComboBox()
        cb.addItems(Qt.GlobalColor.__members__.keys())
        cb.currentTextChanged.connect(self.OnColorChanged)
        toolBar.addWidget(cb)

        toolBar.addWidget(QLabel("Style:"))        
        cb=QComboBox()
        cb.addItems(Qt.BrushStyle.__members__.keys())
        cb.currentTextChanged.connect(self.OnStyleChanged)
        toolBar.addWidget(cb)

        layout.addWidget(toolBar)

        self.brush=QBrush()  
        self.setLayout(layout)
    def paintEvent(self, event: QPaintEvent):
        rect=QRect(50,50,150,150)
        painter=QPainter(self)
        painter.setBrush(self.brush)
        painter.drawRoundedRect(rect,10,10,Qt.SizeMode.RelativeSize)
    def OnColorChanged(self,text):
        color=Qt.GlobalColor[text]
        self.brush.setColor(color)
        self.update()        
        self.parent.OnShowMessage(f"Set Color:{color}")
    def OnStyleChanged(self,text):
        style=Qt.BrushStyle[text]
        self.brush.setStyle(style)
        self.update()        
        self.parent.OnShowMessage(f"Set Style:{style}")

def runDemo(parent):
    wigdet =  Demo(parent)
    return wigdet